package com.blb.edusearchservice.controller;

import com.blb.common.entity.Course;
import com.blb.common.entity.PageEntity;
import com.blb.common.util.ResponseResult;
import com.blb.edusearchservice.service.CourseIndexService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.Map;

@RestController
public class CourseIndexController {

    @Autowired
    private CourseIndexService courseIndexService;

    @GetMapping("init-course-index")
    public ResponseResult<String> initCourseIndex() throws IOException {
        courseIndexService.initCourseIndex();
        return ResponseResult.ok("ok");
    }

    @PostMapping("search-courses")
    public ResponseResult<PageEntity<Course>> searchCourses(@RequestBody Map<String,String> args) throws IOException {
        PageEntity<Course> pageEntity = courseIndexService.searchCourses(args);
        return ResponseResult.ok(pageEntity);
    }
}
